<?php

// tell PHP to log errors to ipn_errors.log in this directory
ini_set('log_errors', true);
ini_set('error_log', dirname(__FILE__).'/ipn_errors.log');

// intantiate the IPN listener
include('ipnlistener.php');
$listener = new IpnListener('cert/api_cert_chain.crt');

// tell the IPN listener to use the PayPal test sandbox
$listener->use_sandbox = true;

// try to process the IPN POST
try {
    $listener->requirePostMethod();
    $verified = $listener->processIpn();
} catch (Exception $e) {
    error_log($e->getMessage());
    exit(0);
}

if ($verified) {
    $errmsg = '';   // stores errors from fraud checks
   
    // 1. Make sure the payment status is "Completed"
    if ($_POST['payment_status'] != 'Completed') {
        // simply ignore any IPN that is not completed
        exit(0);
    }

    // 2. Make sure seller email matches your primary account email.
    if ($_POST['receiver_email'] != '[email protected]') {
        $errmsg .= "'receiver_email' does not match: ";
        $errmsg .= $_POST['receiver_email']."\n";
    }
   
    // 3. Make sure the amount(s) paid match
    if ($_POST['mc_gross'] != '2.00') {
        $errmsg .= "'mc_gross' does not match: ";
        $errmsg .= $_POST['mc_gross']."\n";
    }
   
    // 4. Make sure the currency code matches
    if ($_POST['mc_currency'] != 'USD') {
        $errmsg .= "'mc_currency' does not match: ";
        $errmsg .= $_POST['mc_currency']."\n";
    }

    // TODO: Check for duplicate txn_id
   
    if (!empty($errmsg)) {
   
        // manually investigate errors from the fraud checking
        $body = "IPN failed fraud checks: \n$errmsg\n\n";
        $body .= $listener->getTextReport();
        mail('*****', 'IPN Fraud Warning', $body);
       
    } else {
   
        mail('******', 'all good', 'all good');
       
    }
   
} else {
    // manually investigate the invalid IPN
    mail('*****', 'Invalid IPN', $listener->getTextReport());
    }


זה הקוד לכפתור עצמו
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" target="_top">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="notify_url" value="http://www.****.com/config.php">
<input type="hidden" name="hosted_button_id" value="ES9ZHDD4WREP8">
<input type="image" src="https://www.sandbox.paypal.com/en_US/i/btn/btn_buynow_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.sandbox.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>

1 תשובות

avatar ענה OrelBeY ב 19 לינואר 2014 #

תשתמש בספרייה כמו PHPMailer והחיים שלך יהיו הרבה יותר קלים. יש כאן מדריך על זה ועל משהו שקשור לזה.